﻿using HamcoWcs.Contract.ContractPcon.IPconDbMsgParsers;
using HamcoWcs.Models.Common.Enums;
using HamcoWcs.Models.Devices;
using HamcoWcs.Service.Common;
using System.Collections.Generic;
using System.Linq;

namespace HamcoWcs.Service.Srm.SrmTaskParsers
{
    /// <summary>
    /// Srm消息解析器工厂
    /// </summary>
    [AutoInject(typeof(ISrmParseFactory), InjectType.Scope)]
    public class SrmParseFactory : ISrmParseFactory
    {
        public IEnumerable<ISrmParser> Parsers { get; }

        public SrmParseFactory(IEnumerable<ISrmParser> parsers)
        {
            Parsers = parsers;
        }
        public ISrmParser CreateParser(SrmDto srm)
            => Parsers.FirstOrDefault(x => (int)x.RequestType == srm.Request);
    }
}
